package com.artisan.provider.controller;

import com.artisan.provider.contanent.Contanents;
import com.artisan.provider.covtransformation.CovCouponIntegralExchangeTransformation;
import com.artisan.provider.domain.ZgCouponIntegralExchange;
import com.artisan.provider.dto.ZgCouponIntegralExchangeDto;
import com.artisan.provider.service.ZgCouponIntegralExchangeService;
import com.artisan.provider.utils.Request;
import com.artisan.provider.vo.ZgCouponIntegralExchangeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ZgCouponIntegralExchangeController {

    @Autowired
    ZgCouponIntegralExchangeService zgCouponIntegralExchangeService;



    /***
     * 查询所有优惠券信息
     * @param zgCouponIntegralExchangeDto
     * @param page
     * @param limit
     * @return
     */
    @PostMapping(value = "/api/CouponIntegralExchange/find/all/{page}/{limit}")
    public Request zgCouponIntegralExchangeFindAll(@RequestBody(required = false) ZgCouponIntegralExchangeDto zgCouponIntegralExchangeDto,
                                   @PathVariable(value = "page",required = false) int page,
                                   @PathVariable(value = "limit",required = false)int limit
    ){

        List<ZgCouponIntegralExchange> zgCouponIntegralExchanges = zgCouponIntegralExchangeService.findAll(zgCouponIntegralExchangeDto,page,limit);
        List<ZgCouponIntegralExchangeVo> zgCouponIntegralExchangeVos = CovCouponIntegralExchangeTransformation.INSTANCE.zgCouponIntegralExchangeVos(zgCouponIntegralExchanges);
        if (zgCouponIntegralExchanges != null){
            return new Request(Contanents.DATA_SUCCESS,true,zgCouponIntegralExchangeVos);
        }else{
            return new Request(Contanents.DATA_FAILED,false,new ArrayList<>());
        }

    }

    /**
     * 数据的添加业务
     * @param zgCouponIntegralExchangeDto
     * @return
     */
    @PostMapping(value = "/api/CouponIntegralExchange/add")
    public Request zgCouponIntegralExchangeAdd(@RequestBody ZgCouponIntegralExchangeDto zgCouponIntegralExchangeDto){
        ZgCouponIntegralExchange zgCouponIntegralExchange = CovCouponIntegralExchangeTransformation.INSTANCE.zgCouponIntegralExchange(zgCouponIntegralExchangeDto);
        if(zgCouponIntegralExchangeService.zgCouponIntegralExchangeAdd(zgCouponIntegralExchange) == Contanents.DATA_ADD_REQUEST_ONE){
            return new Request(Contanents.DATA_SUCCESS,true,Contanents.DATA_ADD_REQUEST_ONE);
        }else{
            return new Request(Contanents.DATA_FAILED,false,Contanents.DATA_ADD_REQUEST_ZERO);
        }
    }

    /**
     * 数据的修改业务
     * @param zgCouponIntegralExchangeDto
     * @return
     */
    @PutMapping(value = "/api/CouponIntegralExchange/update")
    public Request zgCouponIntegralExchangeUpdate(@RequestBody ZgCouponIntegralExchangeDto zgCouponIntegralExchangeDto){
        ZgCouponIntegralExchange zgCouponIntegralExchange = CovCouponIntegralExchangeTransformation.INSTANCE.zgCouponIntegralExchange(zgCouponIntegralExchangeDto);
        if(zgCouponIntegralExchangeService.zgCouponIntegralExchangeUpdate(zgCouponIntegralExchange) == Contanents.DATA_ADD_REQUEST_ONE){
            return new Request(Contanents.DATA_SUCCESS,true,Contanents.DATA_ADD_REQUEST_ONE);
        }else{
            return new Request(Contanents.DATA_FAILED,false,Contanents.DATA_ADD_REQUEST_ZERO);
        }
    }

    /**
     * 数据的删除业务
     * @param id
     * @return
     */
    @DeleteMapping(value = "/api/CouponIntegralExchange/delete/{id}")
    public Request zgCouponIntegralExchangeDelete(@PathVariable(value = "id")int id){

        if(zgCouponIntegralExchangeService.zgCouponIntegralExchangeDelete(id) == Contanents.DATA_ADD_REQUEST_ONE){
            return new Request(Contanents.DATA_SUCCESS,true,Contanents.DATA_ADD_REQUEST_ONE);
        }else{
            return new Request(Contanents.DATA_FAILED,false,Contanents.DATA_ADD_REQUEST_ZERO);
        }
    }

}
